/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[][]}
 */
 var levelOrder = function(root) {
    let res = []
    let queue = []
    if(root ==null){
        return res
    }
    queue.unshift(root)
    while(queue.length!==0){
        let curLevel = [];
        let len = queue.length
        for(let i= 0;i<len;i++){
            let node = queue.pop()
            curLevel.push(node.val)
            node.left&&queue.unshift(node.left)
            node.right&&queue.unshift(node.right)
        }
        res.push(curLevel)
    }
    return res;
};